package 链表;

/**
 * https://leetcode-cn.com/problems/intersection-of-two-linked-lists/
 *
 * @author Mxb
 * @version 1.0
 * @date 2020/3/4 21:58
 */
public class _160_相交链表 {

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode l1 = headA, l2 = headB;
        //while (l1 != l2) {
        //    l1 = (l1 == null) ? headB : l1.next;
        //    l2 = (l2 == null) ? headA : l2.next;
        //}
        //return l1;

        while (l1 != l2) {
            if(l1==null){
                l1= headB;
            }else{
                l1 = l1.next;
            }
            if(l2==null){
                l2= headA;
            }else{
                l2 = l2.next;
            }
        }
        return l1;
    }
}
